﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TSL.AjaxResult.KaiJiang
{
    public class KaiJiang4
    {
        public static int OpenJJ(string caipiao_name, string codes, string buycodes)
        {
            switch (caipiao_name)
            {
                case "任二":
                    return RenEr(codes, buycodes);

                case "任三":
                    return RenSan(codes, buycodes);

                case "任四":
                    return RenSi(codes, buycodes);

                case "任五":
                    return RenWu(codes, buycodes);

                case "任一":
                    return RenYi(codes, buycodes);

                case "任六":
                    return RenLiu(codes, buycodes);

                case "任七":
                    return RenQi(codes, buycodes);

                case "任八":
                    return RenBa(codes, buycodes);

                case "任九":
                    return RenJiu(codes, buycodes);

                case "任十":
                    return RenShi(codes, buycodes);
            }
            return 0;
        }

        public static int RenBa(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenEr(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 2)
                {
                    winbonus += (win * (win - 1)) / 2;
                }
            }
            return winbonus;
        }

        public static int RenJiu(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenLiu(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenQi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenSan(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 3)
                {
                    winbonus += (win * (win - 1)) / 6;
                }
            }
            return winbonus;
        }

        public static int RenShi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenSi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 4)
                {
                    winbonus += (win * (win - 1)) / 12;
                }
            }
            return winbonus;
        }

        public static int RenWu(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win == 5)
                {
                    winbonus++;
                }
            }
            return winbonus;
        }

        public static int RenYi(string codes, string buycodes)
        {
            string[] code = codes.Split(new char[] { ',' });
            string[] mycode = buycodes.Split(new char[] { '$' });
            string _code = string.Empty;
            int winbonus = 0;
            int win = 0;
            for (int i = 0; i < mycode.Length; i++)
            {
                win = 0;
                for (int j = 0; j < code.Length; j++)
                {
                    _code = code[j].ToString().Trim() + " ";
                    if ((mycode[i].ToString().Trim() + " ").IndexOf(_code) != -1)
                    {
                        win++;
                    }
                }
                if (win >= 1)
                {
                    winbonus += (win * (win - 1)) / 2;
                }
            }
            return winbonus;
        }
    }
}
